home *** CD-ROM | disk | FTP | other *** search
- Path: rover.ucs.ualberta.ca!alberta!wong
- From: wong@cs.ualberta.ca (Warren Wong)
- Newsgroups: comp.lang.c++,de.comp.lang.c++,ualberta.cmput.201
- Subject: Re: Another function pointer from a class question?!
- Date: 31 Mar 1996 20:35:57 GMT
- Organization: Computing Science, U of Alberta, Edmonton, Canada
- Message-ID: <4jmqbd$lrk@scapa.cs.ualberta.ca>
- References: <4jls2p$bac@pulp.ucs.ualberta.ca>
- NNTP-Posting-Host: sawnlk.cs.ualberta.ca
-
- ryangall@gpu.srv.ualberta.ca (Ryan Gallagher) writes:
-
- >well....its just that I get a linker error when I try and run it when
- >using
- >the print function. Since I want to be able to use any structure for
- >the list, I will have to supply some sort of printing function to the
- >class,
- >otherwise, it will not nessesarily know what to do when printing each
- >member.
- >Anyways, this is my first attempt at a template, and derived class....so
- >bear with me if I've made any really stupid mistakes.
-
- [some stuff]
-
- >template<class T>
- >// I used to have this next line, as the delaration but it didnt work,
- >//class dl_list : public list<T>{
- >// it kept saying that I couldnt use a abstract class directly.
-
- >class dl_list{
- > struct node{
- > T data;
- > node *next;
- > node *prev;
- > node(T d,node *n,node *p) { data = d; next = n; prev =p;}
- > };
-
- > node *S;
- > node *F;
- > node *C;
-
- >public:
-
- > dl_list();
- > ~dl_list();
-
- > int Add(T);
- > T Remove();
- > T POPfirst();
- > T POPlast();
- > int empty() { return (F==S); }
- > void print(void (*)(T));
-
- >};
-
- >/***********************************************************************
- >*
- >* print: prints off the data in the list.
- >*
- >************************************************************************/
-
- >template<class T> void list<T>::print(void (*pfunc)(T))
- > {
- > node *X=S;
-
- > cout << endl << endl <<endl;
- > cout << "THE LIST" << endl << "--------" << endl;
-
-
- > if(X!=F)
-
- > do
- > {
- > X=X->next;
- > (*pfunc)(X->data);
- > }
- > while( X != F && X);
-
- > return 0;
-
- > }
-
- >//*************************************************************
-
- >void printint(int d)
- >{
- > printf("( %i )\n",d);
- >}
-
- It looks like you forgot to write the template function for the dl_list
- print function to actually call the function pointer. You did it for
- the list, but since you're not deriving the dl_list from the list (I
- think you commented it out) you're not calling that functions. You just
- have to make a template for the print function.
-
- -WW
-
- --
- Warren Wong
- wong@cs.ualberta.ca
-
-